<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- saved from url=(0062)http://www.cnblogs.com/hustcat/archive/2009/02/26/1398558.html -->
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-cn"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><script async="" src="./SQLite入门与分析(四)---Page Cache之事务处理(1) - YY哥 - 博客园_files/widget"></script>

<title>SQLite入门与分析(四)---Page Cache之事务处理(1)  - YY哥 - 博客园</title>
<link type="text/css" rel="stylesheet" href="./SQLite入门与分析(四)---Page Cache之事务处理(1) - YY哥 - 博客园_files/blog-common.css">
<link id="MainCss" type="text/css" rel="stylesheet" href="./SQLite入门与分析(四)---Page Cache之事务处理(1) - YY哥 - 博客园_files/bundle-ClassicBlue.css">
<link title="RSS" type="application/rss+xml" rel="alternate" href="http://www.cnblogs.com/hustcat/rss">
<link title="RSD" type="application/rsd+xml" rel="EditURI" href="http://www.cnblogs.com/hustcat/rsd.xml">
<link type="application/wlwmanifest+xml" rel="wlwmanifest" href="http://www.cnblogs.com/hustcat/wlwmanifest.xml">
<script async="" src="./SQLite入门与分析(四)---Page Cache之事务处理(1) - YY哥 - 博客园_files/analytics.js"></script><script type="text/javascript" src="./SQLite入门与分析(四)---Page Cache之事务处理(1) - YY哥 - 博客园_files/encoder.js"></script><script src="./SQLite入门与分析(四)---Page Cache之事务处理(1) - YY哥 - 博客园_files/jquery.js" type="text/javascript"></script>  
<script type="text/javascript">var currentBlogApp = 'hustcat', cb_enable_mathjax=false;</script>
<script src="./SQLite入门与分析(四)---Page Cache之事务处理(1) - YY哥 - 博客园_files/blog-common.js" type="text/javascript"></script>
</head>
<body>
<a name="top"></a>

<!--done-->
<div id="home">
<div id="header">
	<div id="blogTitle">
	<a id="lnkBlogLogo" href="http://www.cnblogs.com/hustcat/"><img id="blogLogo" src="./SQLite入门与分析(四)---Page Cache之事务处理(1) - YY哥 - 博客园_files/logo.gif" alt="返回主页"></a>			
		
<!--done-->
<h1><a id="Header1_HeaderTitle" class="headermaintitle" href="http://www.cnblogs.com/hustcat/">YY哥的技术随笔</a></h1>
<h2>——关注Linux、数据库和云计算</h2>



		
	</div><!--end: blogTitle 博客的标题和副标题 -->
	<div id="navigator">
		
<ul id="navList">
<li><a id="MyLinks1_HomeLink" class="menu" href="http://www.cnblogs.com/">博客园</a></li>
<li><a id="MyLinks1_MyHomeLink" class="menu" href="http://www.cnblogs.com/hustcat/">首页</a></li>
<li><a id="MyLinks1_NewPostLink" class="menu" rel="nofollow" href="http://i.cnblogs.com/EditPosts.aspx?opt=1">新随笔</a></li>
<li><a id="MyLinks1_ContactLink" class="menu" rel="nofollow" href="http://msg.cnblogs.com/send/YY%E5%93%A5">联系</a></li>
<li><a id="MyLinks1_Syndication" class="menu" href="http://www.cnblogs.com/hustcat/rss">订阅</a>
<!--<a id="MyLinks1_XMLLink" class="aHeaderXML" href="http://www.cnblogs.com/hustcat/rss"><img src="http://www.cnblogs.com/images/xml.gif" alt="订阅" /></a>--></li>
<li><a id="MyLinks1_Admin" class="menu" rel="nofollow" href="http://i.cnblogs.com/">管理</a></li>
</ul>
		<div class="blogStats">
			
			
<!--done-->
随笔- 125&nbsp;
文章- 114&nbsp;
评论- 378&nbsp;

			
		</div><!--end: blogStats -->
	</div><!--end: navigator 博客导航栏 -->
</div><!--end: header 头部 -->

<div id="main">
	<div id="mainContent">
	<div class="forFlow">
		
<div id="post_detail">
<!--done-->
<div id="topics">
	<div class="post">
		<h1 class="postTitle">
			<a id="cb_post_title_url" class="postTitle2" href="./SQLite入门与分析(四)---Page Cache之事务处理(1) - YY哥 - 博客园_files/SQLite入门与分析(四)---Page Cache之事务处理(1) - YY哥 - 博客园.html">SQLite入门与分析(四)---Page Cache之事务处理(1) </a>
		</h1>
		<div class="clear"></div>
		<div class="postBody">
			<div id="cnblogs_post_body"><p><font face="Verdana">写在前面：从本章开始，将对SQLite的每个模块进行讨论。讨论的顺序按照我阅读SQLite的顺序来进行，由于项目的需要，以及时间关系，不能给出一个完整的计划，但是我会先讨论我认为比较重要的内容。本节讨论SQLite的事务处理技术，事务处理是DBMS中最关键的技术，对SQLite也一样，它涉及到并发控制，以及故障恢复，由于内容较多，分为两节。好了，下面进入正题。</font></p>
<p><font face="Verdana">&nbsp;本节通过一个具体的例子来分析SQLite原子提交的实现（基于Version 3.3.6的代码）。<br>
CREATE TABLE episodes( id integer primary key,name text, cid int) ；<br>
插入一条记录：insert into episodes(name,cid) values("cat",1) ;<br>
它经过编译器处理后生成的虚拟机代码如下：<br>
sqlite&gt; explain insert into episodes(name,cid) values("cat",1);<br>
0|Trace|0|0|0|explain insert into episodes(name,cid) values("cat",1);|00|<br>
1|Goto|0|12|0||00|<br>
2|SetNumColumns|0|3|0||00|<br>
<span style="color: red">3|OpenWrite|0|2|0||00|<br>
</span>4|NewRowid|0|2|0||00|<br>
5|Null|0|3|0||00|<br>
6|String8|0|4|0|cat|00|<br>
7|Integer|1|5|0||00|<br>
8|MakeRecord|3|3|6|dad|00|<br>
<span style="color: red">9|Insert|0|6|2|episodes|0b|</span><br>
10|Close|0|0|0||00|<br>
<span style="color: red">11|Halt|0|0|0||00|<br>
</span><span style="color: red">12|Transaction|0|1|0||00|<br>
</span>13|VerifyCookie|0|1|0||00|<br>
14|Transaction|1|1|0||00|<br>
15|VerifyCookie|1|0|0||00|</font></p>
<p><font face="Verdana">16|TableLock|0|2|1|episodes|00|</font></p>
<p><font face="Verdana">17|Goto|0|2|0||00|</font></p>
<p><font face="Verdana">&nbsp;</font></p>
<p><font face="Verdana"><span style="color: red"><font face="Verdana">1、初始状态（Initial State）<br>
</font></span>当一个数据库连接第一次打开时，状态如图所示。图中最右边（“Disk”标注）表示保存在存储设备中的内容。每个方框代表一个扇区。蓝色的块表示这个扇区保存了原始数据。图中中间区域是操作系统的磁盘缓冲区。开始的时候，这些缓存是还没有被使用，因此这些方框是空白的。图中左边区域显示SQLite用户进程的内存。因为这个数据库连接刚刚打开，所以还没有任何数据记录被读入，所以这些内存也是空的。</font></p>
<p><font face="Verdana">&nbsp;<img height="270" alt="" src="./SQLite入门与分析(四)---Page Cache之事务处理(1) - YY哥 - 博客园_files/commit-0.gif" width="295" border="0"></font></p>
<p><font face="Verdana"><span style="color: red"><font face="Verdana">2</font></span><span style="color: red">、获取读锁(Acquiring A Read Lock)<br>
</span>在SQLite写数据库之前，它必须先从数据库中读取相关信息。比如，在插入新的数据时，SQLite会先从sqlite_master表中读取数据库模式(相当于数据字典)，以便编译器对INSERT语句进行分析，确定数据插入的位置。<br>
在进行读操作之前，必须先获取数据库的共享锁(shared lock)，共享锁允许两个或更多的连接在同一时刻读取数据库。但是共享锁不允许其它连接对数据库进行写操作。<br>
shared lock存在于操作系统磁盘缓存，而不是磁盘本身。文件锁的本质只是操作系统的内核数据结构，当操作系统崩溃或掉电时，这些内核数据也会随之消失。</font></p>
<p><font face="Verdana"><font face="Verdana"><img height="270" alt="" src="./SQLite入门与分析(四)---Page Cache之事务处理(1) - YY哥 - 博客园_files/commit-1.gif" width="295" border="0"></font><br>
&nbsp;</font></p><font face="Verdana">
<p>&nbsp;<font face="Verdana"><span style="color: red"><font face="Verdana">3、读取数据</font></span><br>
一旦得到shared lock，就可以进行读操作。如图所示，数据先由OS从磁盘读取到OS缓存，然后再由OS移到用户进程空间。一般来说，数据库文件分为很多页，而一次读操作只读取一小部分页面。如图，从8个页面读取3个页面。<br>
<img height="270" alt="" src="./SQLite入门与分析(四)---Page Cache之事务处理(1) - YY哥 - 博客园_files/commit-2.gif" width="295" border="0"></font></p>
<p><font face="Verdana"><span style="color: red"><font face="Verdana">4、获取Reserved Lock<br>
</font></span>在对数据进行修改操作之前，先要获取数据库文件的Reserved Lock，Reserved Lock和shared lock的相似之处在于，它们都允许其它进程对数据库文件进行读操作。Reserved Lock和Shared Lock可以共存，但是只能是一个Reserved Lock和多个Shared Lock——多个Reserved Lock不能共存。所以，在同一时刻，只能进行一个写操作。<br>
Reserved Lock意味着当前进程(连接)想修改数据库文件，但是还没开始修改操作，所以其它的进程可以读数据库，但不能写数据库。<br>
<img height="270" alt="" src="./SQLite入门与分析(四)---Page Cache之事务处理(1) - YY哥 - 博客园_files/commit-3.gif" width="295" border="0"></font></p>
<p><font face="Verdana"><span style="color: red"><font face="Verdana">5、创建恢复日志(Creating A Rollback Journal File)<br>
</font></span>在对数据库进行写操作之前，SQLite先要创建一个单独的日志文件，然后把要修改的页面的原始数据写入日志。回滚日志包含一个日志头(图中的绿色)——记录数据库文件的原始大小。所以即使数据库文件大小改变了，我们仍知道数据库的原始大小。<br>
从OS的角度来看，当一个文件创建时，大多数OS(Windows,Linux,Mac OS X)不会向磁盘写入数据，新创建的文件此时位于磁盘缓存中，之后才会真正写入磁盘。如图，日志文件位于OS磁盘缓存中，而不是位于磁盘。<br>
</font></p>
<p><img height="351" alt="" src="./SQLite入门与分析(四)---Page Cache之事务处理(1) - YY哥 - 博客园_files/commit-4.gif" width="295" border="0"></p>
<p>上面 5步的代码的实现：</p>
<p>&nbsp;</p>
<div class="cnblogs_code"><img id="Code_Closed_Image_104228" onclick="this.style.display=&#39;none&#39;; document.getElementById(&#39;Code_Closed_Text_104228&#39;).style.display=&#39;none&#39;; document.getElementById(&#39;Code_Open_Image_104228&#39;).style.display=&#39;inline&#39;; document.getElementById(&#39;Code_Open_Text_104228&#39;).style.display=&#39;inline&#39;;" height="16" src="./SQLite入门与分析(四)---Page Cache之事务处理(1) - YY哥 - 博客园_files/ContractedBlock.gif" width="11" align="top"><img id="Code_Open_Image_104228" style="display: none" onclick="this.style.display=&#39;none&#39;; document.getElementById(&#39;Code_Open_Text_104228&#39;).style.display=&#39;none&#39;; getElementById(&#39;Code_Closed_Image_104228&#39;).style.display=&#39;inline&#39;; getElementById(&#39;Code_Closed_Text_104228&#39;).style.display=&#39;inline&#39;;" height="16" src="./SQLite入门与分析(四)---Page Cache之事务处理(1) - YY哥 - 博客园_files/ExpandedBlockStart.gif" width="11" align="top"><span class="cnblogs_code_Collapse" id="Code_Closed_Text_104228">Code</span><span id="Code_Open_Text_104228" style="display: none"><br>
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008000">//</span><span style="color: #008000">事务指令的实现<br>
</span><span style="color: #008000">//</span><span style="color: #008000">p1为数据库文件的索引号---0为main&nbsp;database;1为temporary&nbsp;tables使用的文件<br>
</span><span style="color: #008000">//</span><span style="color: #008000">p2&nbsp;不为0，一个写事务开始</span><span style="color: #008000"><br>
</span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;OP_Transaction:&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">数据库的索引号</span><span style="color: #008000"><br>
</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;pOp</span><span style="color: #000000">-&gt;</span><span style="color: #000000">p1;<br>
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">指向数据库对应的btree</span><span style="color: #008000"><br>
</span><span style="color: #000000">&nbsp;&nbsp;Btree&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">pBt;<br>
<br>
&nbsp;&nbsp;assert(&nbsp;i</span><span style="color: #000000">&gt;=</span><span style="color: #800080">0</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">db</span><span style="color: #000000">-&gt;</span><span style="color: #000000">nDb&nbsp;);<br>
&nbsp;&nbsp;assert(&nbsp;(p</span><span style="color: #000000">-&gt;</span><span style="color: #000000">btreeMask&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">&nbsp;(</span><span style="color: #800080">1</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">i))</span><span style="color: #000000">!=</span><span style="color: #800080">0</span><span style="color: #000000">&nbsp;);<br>
&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">设置btree指针</span><span style="color: #008000"><br>
</span><span style="color: #000000">&nbsp;&nbsp;pBt&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;db</span><span style="color: #000000">-&gt;</span><span style="color: #000000">aDb[i].pBt;<br>
<br>
&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;pBt&nbsp;){<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">从这里btree开始事务,主要给文件加锁,并设置btree事务状态</span><span style="color: #008000"><br>
</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;rc&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;sqlite3BtreeBeginTrans(pBt,&nbsp;pOp</span><span style="color: #000000">-&gt;</span><span style="color: #000000">p2);<br>
&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;rc</span><span style="color: #000000">==</span><span style="color: #000000">SQLITE_BUSY&nbsp;){<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p</span><span style="color: #000000">-&gt;</span><span style="color: #000000">pc&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;pc;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p</span><span style="color: #000000">-&gt;</span><span style="color: #000000">rc&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;rc&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;SQLITE_BUSY;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">goto</span><span style="color: #000000">&nbsp;vdbe_return;<br>
&nbsp;&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;rc</span><span style="color: #000000">!=</span><span style="color: #000000">SQLITE_OK&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;rc</span><span style="color: #000000">!=</span><span style="color: #000000">SQLITE_READONLY&nbsp;</span><span style="color: #008000">/*</span><span style="color: #008000">&nbsp;&amp;&amp;&nbsp;rc!=SQLITE_BUSY&nbsp;</span><span style="color: #008000">*/</span><span style="color: #000000">&nbsp;){<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">goto</span><span style="color: #000000">&nbsp;abort_due_to_error;<br>
&nbsp;&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;}<br>
&nbsp;&nbsp;</span><span style="color: #0000ff">break</span><span style="color: #000000">;<br>
}<br>
<br>
</span><span style="color: #008000">//</span><span style="color: #008000">开始一个事务,如果第二个参数不为0,则一个写事务开始,否则是一个读事务<br>
</span><span style="color: #008000">//</span><span style="color: #008000">如果wrflag&gt;=2,一个exclusive事务开始,此时别的连接不能访问数据库</span><span style="color: #008000"><br>
</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;sqlite3BtreeBeginTrans(Btree&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">p,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;wrflag){<br>
&nbsp;&nbsp;BtShared&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">pBt&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;p</span><span style="color: #000000">-&gt;</span><span style="color: #000000">pBt;<br>
&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;rc&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;SQLITE_OK;<br>
<br>
&nbsp;&nbsp;btreeIntegrity(p);<br>
<br>
&nbsp;&nbsp;</span><span style="color: #008000">/*</span><span style="color: #008000">&nbsp;If&nbsp;the&nbsp;btree&nbsp;is&nbsp;already&nbsp;in&nbsp;a&nbsp;write-transaction,&nbsp;or&nbsp;it<br>
&nbsp;&nbsp;**&nbsp;is&nbsp;already&nbsp;in&nbsp;a&nbsp;read-transaction&nbsp;and&nbsp;a&nbsp;read-transaction<br>
&nbsp;&nbsp;**&nbsp;is&nbsp;requested,&nbsp;this&nbsp;is&nbsp;a&nbsp;no-op.<br>
&nbsp;&nbsp;</span><span style="color: #008000">*/</span><span style="color: #000000"><br>
&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">如果b-tree处于一个写事务;或者处于一个读事务,一个读事务又请求,则返回SQLITE_OK</span><span style="color: #008000"><br>
</span><span style="color: #000000">&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;p</span><span style="color: #000000">-&gt;</span><span style="color: #000000">inTrans</span><span style="color: #000000">==</span><span style="color: #000000">TRANS_WRITE&nbsp;</span><span style="color: #000000">||</span><span style="color: #000000">&nbsp;(p</span><span style="color: #000000">-&gt;</span><span style="color: #000000">inTrans</span><span style="color: #000000">==</span><span style="color: #000000">TRANS_READ&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">!</span><span style="color: #000000">wrflag)&nbsp;){<br>
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;SQLITE_OK;<br>
&nbsp;&nbsp;}<br>
<br>
&nbsp;&nbsp;</span><span style="color: #008000">/*</span><span style="color: #008000">&nbsp;Write&nbsp;transactions&nbsp;are&nbsp;not&nbsp;possible&nbsp;on&nbsp;a&nbsp;read-only&nbsp;database&nbsp;</span><span style="color: #008000">*/</span><span style="color: #000000"><br>
&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">写事务不能访问只读数据库</span><span style="color: #008000"><br>
</span><span style="color: #000000">&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;pBt</span><span style="color: #000000">-&gt;</span><span style="color: #000000">readOnly&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;wrflag&nbsp;){<br>
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;SQLITE_READONLY;<br>
&nbsp;&nbsp;}<br>
<br>
&nbsp;&nbsp;</span><span style="color: #008000">/*</span><span style="color: #008000">&nbsp;If&nbsp;another&nbsp;database&nbsp;handle&nbsp;has&nbsp;already&nbsp;opened&nbsp;a&nbsp;write&nbsp;transaction&nbsp;<br>
&nbsp;&nbsp;**&nbsp;on&nbsp;this&nbsp;shared-btree&nbsp;structure&nbsp;and&nbsp;a&nbsp;second&nbsp;write&nbsp;transaction&nbsp;is<br>
&nbsp;&nbsp;**&nbsp;requested,&nbsp;return&nbsp;SQLITE_BUSY.<br>
&nbsp;&nbsp;</span><span style="color: #008000">*/</span><span style="color: #000000"><br>
&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">如果数据库已存在一个写事务,则该写事务请求时返回SQLITE_BUSY</span><span style="color: #008000"><br>
</span><span style="color: #000000">&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;pBt</span><span style="color: #000000">-&gt;</span><span style="color: #000000">inTransaction</span><span style="color: #000000">==</span><span style="color: #000000">TRANS_WRITE&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;wrflag&nbsp;){<br>
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;SQLITE_BUSY;<br>
&nbsp;&nbsp;}<br>
<br>
&nbsp;&nbsp;</span><span style="color: #0000ff">do</span><span style="color: #000000">&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">如果数据库对应btree的第一个页面还没读进内存<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">则把该页面读进内存，数据库也相应的加read&nbsp;lock</span><span style="color: #008000"><br>
</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;pBt</span><span style="color: #000000">-&gt;</span><span style="color: #000000">pPage1</span><span style="color: #000000">==</span><span style="color: #800080">0</span><span style="color: #000000">&nbsp;){<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">加read&nbsp;lock，并读页面到内存</span><span style="color: #008000"><br>
</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rc&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;lockBtree(pBt);<br>
&nbsp;&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;rc</span><span style="color: #000000">==</span><span style="color: #000000">SQLITE_OK&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;wrflag&nbsp;){<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">对数据库文件加RESERVED_LOCK锁</span><span style="color: #008000"><br>
</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rc&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;sqlite3pager_begin(pBt</span><span style="color: #000000">-&gt;</span><span style="color: #000000">pPage1</span><span style="color: #000000">-&gt;</span><span style="color: #000000">aData,&nbsp;wrflag</span><span style="color: #000000">&gt;</span><span style="color: #800080">1</span><span style="color: #000000">);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;rc</span><span style="color: #000000">==</span><span style="color: #000000">SQLITE_OK&nbsp;){<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rc&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;newDatabase(pBt);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;rc</span><span style="color: #000000">==</span><span style="color: #000000">SQLITE_OK&nbsp;){<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;wrflag&nbsp;)&nbsp;pBt</span><span style="color: #000000">-&gt;</span><span style="color: #000000">inStmt&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #800080">0</span><span style="color: #000000">;<br>
&nbsp;&nbsp;&nbsp;&nbsp;}</span><span style="color: #0000ff">else</span><span style="color: #000000">{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;unlockBtreeIfUnused(pBt);<br>
&nbsp;&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;}</span><span style="color: #0000ff">while</span><span style="color: #000000">(&nbsp;rc</span><span style="color: #000000">==</span><span style="color: #000000">SQLITE_BUSY&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;pBt</span><span style="color: #000000">-&gt;</span><span style="color: #000000">inTransaction</span><span style="color: #000000">==</span><span style="color: #000000">TRANS_NONE&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000"><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sqlite3InvokeBusyHandler(pBt</span><span style="color: #000000">-&gt;</span><span style="color: #000000">pBusyHandler)&nbsp;);<br>
<br>
&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;rc</span><span style="color: #000000">==</span><span style="color: #000000">SQLITE_OK&nbsp;){<br>
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;p</span><span style="color: #000000">-&gt;</span><span style="color: #000000">inTrans</span><span style="color: #000000">==</span><span style="color: #000000">TRANS_NONE&nbsp;){<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">btree的事务数加1</span><span style="color: #008000"><br>
</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pBt</span><span style="color: #000000">-&gt;</span><span style="color: #000000">nTransaction</span><span style="color: #000000">++</span><span style="color: #000000">;<br>
&nbsp;&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">设置btree事务状态</span><span style="color: #008000"><br>
</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;p</span><span style="color: #000000">-&gt;</span><span style="color: #000000">inTrans&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(wrflag</span><span style="color: #000000">?</span><span style="color: #000000">TRANS_WRITE:TRANS_READ);<br>
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;p</span><span style="color: #000000">-&gt;</span><span style="color: #000000">inTrans</span><span style="color: #000000">&gt;</span><span style="color: #000000">pBt</span><span style="color: #000000">-&gt;</span><span style="color: #000000">inTransaction&nbsp;){<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pBt</span><span style="color: #000000">-&gt;</span><span style="color: #000000">inTransaction&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;p</span><span style="color: #000000">-&gt;</span><span style="color: #000000">inTrans;<br>
&nbsp;&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;}<br>
<br>
&nbsp;&nbsp;btreeIntegrity(p);<br>
&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;rc;<br>
}<br>
<br>
</span><span style="color: #008000">/*</span><span style="color: #008000"><br>
**获取数据库的写锁,发生以下情况时去除写锁:<br>
**&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;sqlite3pager_commit()&nbsp;is&nbsp;called.<br>
**&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;sqlite3pager_rollback()&nbsp;is&nbsp;called.<br>
**&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;sqlite3pager_close()&nbsp;is&nbsp;called.<br>
**&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;sqlite3pager_unref()&nbsp;is&nbsp;called&nbsp;to&nbsp;on&nbsp;every&nbsp;outstanding&nbsp;page.<br>
**&nbsp;&nbsp;&nbsp;pData指向数据库的打开的页面,此时并不修改,仅仅只是获取<br>
**&nbsp;&nbsp;&nbsp;相应的pager,检查它是否处于read-lock状态。<br>
**如果打开的不是临时文件,则打开日志文件.<br>
**如果数据库已经处于写状态，则do&nbsp;nothing<br>
</span><span style="color: #008000">*/</span><span style="color: #000000"><br>
</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;sqlite3pager_begin(</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">pData,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;exFlag){<br>
&nbsp;&nbsp;PgHdr&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">pPg&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;DATA_TO_PGHDR(pData);<br>
&nbsp;&nbsp;Pager&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">pPager&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;pPg</span><span style="color: #000000">-&gt;</span><span style="color: #000000">pPager;<br>
&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;rc&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;SQLITE_OK;<br>
&nbsp;&nbsp;assert(&nbsp;pPg</span><span style="color: #000000">-&gt;</span><span style="color: #000000">nRef</span><span style="color: #000000">&gt;</span><span style="color: #800080">0</span><span style="color: #000000">&nbsp;);<br>
&nbsp;&nbsp;assert(&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">state</span><span style="color: #000000">!=</span><span style="color: #000000">PAGER_UNLOCK&nbsp;);<br>
&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">pager已经处于share状态</span><span style="color: #008000"><br>
</span><span style="color: #000000">&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">state</span><span style="color: #000000">==</span><span style="color: #000000">PAGER_SHARED&nbsp;){<br>
&nbsp;&nbsp;&nbsp;&nbsp;assert(&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">aInJournal</span><span style="color: #000000">==</span><span style="color: #800080">0</span><span style="color: #000000">&nbsp;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;MEMDB&nbsp;){<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">state&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;PAGER_EXCLUSIVE;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">origDbSize&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">dbSize;<br>
&nbsp;&nbsp;&nbsp;&nbsp;}</span><span style="color: #0000ff">else</span><span style="color: #000000">{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">对文件加&nbsp;RESERVED_LOCK</span><span style="color: #008000"><br>
</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rc&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;sqlite3OsLock(pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">fd,&nbsp;RESERVED_LOCK);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;rc</span><span style="color: #000000">==</span><span style="color: #000000">SQLITE_OK&nbsp;){<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">设置pager的状态</span><span style="color: #008000"><br>
</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">state&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;PAGER_RESERVED;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;exFlag&nbsp;){<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rc&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;pager_wait_on_lock(pPager,&nbsp;EXCLUSIVE_LOCK);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;rc</span><span style="color: #000000">!=</span><span style="color: #000000">SQLITE_OK&nbsp;){<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;rc;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">dirtyCache&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #800080">0</span><span style="color: #000000">;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TRACE2(</span><span style="color: #800000">"</span><span style="color: #800000">TRANSACTION&nbsp;%d\n</span><span style="color: #800000">"</span><span style="color: #000000">,&nbsp;PAGERID(pPager));<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">使用日志,不是临时文件,则打开日志文件</span><span style="color: #008000"><br>
</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">useJournal&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">!</span><span style="color: #000000">pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">tempFile&nbsp;){<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">为pager打开日志文件,pager应该处于RESERVED或EXCLUSIVE状态<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">会向日志文件写入header</span><span style="color: #008000"><br>
</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rc&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;pager_open_journal(pPager);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;}<br>
&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;rc;<br>
}<br>
<br>
<br>
</span><span style="color: #008000">//</span><span style="color: #008000">创建日志文件,pager应该处于RESERVED或EXCLUSIVE状态</span><span style="color: #008000"><br>
</span><span style="color: #0000ff">static</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;pager_open_journal(Pager&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">pPager){<br>
&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;rc;<br>
&nbsp;&nbsp;assert(&nbsp;</span><span style="color: #000000">!</span><span style="color: #000000">MEMDB&nbsp;);<br>
&nbsp;&nbsp;assert(&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">state</span><span style="color: #000000">&gt;=</span><span style="color: #000000">PAGER_RESERVED&nbsp;);<br>
&nbsp;&nbsp;assert(&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">journalOpen</span><span style="color: #000000">==</span><span style="color: #800080">0</span><span style="color: #000000">&nbsp;);<br>
&nbsp;&nbsp;assert(&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">useJournal&nbsp;);<br>
&nbsp;&nbsp;assert(&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">aInJournal</span><span style="color: #000000">==</span><span style="color: #800080">0</span><span style="color: #000000">&nbsp;);<br>
&nbsp;&nbsp;sqlite3pager_pagecount(pPager);<br>
&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">日志文件页面位图</span><span style="color: #008000"><br>
</span><span style="color: #000000">&nbsp;&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">aInJournal&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;sqliteMalloc(&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">dbSize</span><span style="color: #000000">/</span><span style="color: #800080">8</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #800080">1</span><span style="color: #000000">&nbsp;);<br>
&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">aInJournal</span><span style="color: #000000">==</span><span style="color: #800080">0</span><span style="color: #000000">&nbsp;){<br>
&nbsp;&nbsp;&nbsp;&nbsp;rc&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;SQLITE_NOMEM;<br>
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">goto</span><span style="color: #000000">&nbsp;failed_to_open_journal;<br>
&nbsp;&nbsp;}<br>
&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">打开日志文件</span><span style="color: #008000"><br>
</span><span style="color: #000000">&nbsp;&nbsp;rc&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;sqlite3OsOpenExclusive(pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">zJournal,&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">jfd,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">tempFile);<br>
&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">日志文件的位置指针</span><span style="color: #008000"><br>
</span><span style="color: #000000">&nbsp;&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">journalOff&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #800080">0</span><span style="color: #000000">;<br>
&nbsp;&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">setMaster&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #800080">0</span><span style="color: #000000">;<br>
&nbsp;&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">journalHdr&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #800080">0</span><span style="color: #000000">;<br>
&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;rc</span><span style="color: #000000">!=</span><span style="color: #000000">SQLITE_OK&nbsp;){<br>
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">goto</span><span style="color: #000000">&nbsp;failed_to_open_journal;<br>
&nbsp;&nbsp;}<br>
&nbsp;&nbsp;</span><span style="color: #008000">/*</span><span style="color: #008000">一般来说，os此时创建的文件位于磁盘缓存，并没有实际<br>
&nbsp;&nbsp;**存在于磁盘,下面三个操作就是为了把结果写入磁盘,而对于<br>
&nbsp;&nbsp;**windows系统来说,并没有提供相应API，所以实际上没有意义.<br>
&nbsp;&nbsp;</span><span style="color: #008000">*/</span><span style="color: #000000"><br>
&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">fullSync操作对windows没有意义</span><span style="color: #008000"><br>
</span><span style="color: #000000">&nbsp;&nbsp;sqlite3OsSetFullSync(pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">jfd,&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">full_fsync);<br>
&nbsp;&nbsp;sqlite3OsSetFullSync(pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">fd,&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">full_fsync);<br>
&nbsp;&nbsp;</span><span style="color: #008000">/*</span><span style="color: #008000">&nbsp;Attempt&nbsp;to&nbsp;open&nbsp;a&nbsp;file&nbsp;descriptor&nbsp;for&nbsp;the&nbsp;directory&nbsp;that&nbsp;contains&nbsp;a&nbsp;file.&nbsp;<br>
&nbsp;&nbsp;**This&nbsp;file&nbsp;descriptor&nbsp;can&nbsp;be&nbsp;used&nbsp;to&nbsp;fsync()&nbsp;the&nbsp;directory<br>
&nbsp;&nbsp;**in&nbsp;order&nbsp;to&nbsp;make&nbsp;sure&nbsp;the&nbsp;creation&nbsp;of&nbsp;a&nbsp;new&nbsp;file&nbsp;is&nbsp;actually&nbsp;written&nbsp;&nbsp;to&nbsp;disk.<br>
&nbsp;&nbsp;</span><span style="color: #008000">*/</span><span style="color: #000000"><br>
&nbsp;&nbsp;sqlite3OsOpenDirectory(pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">jfd,&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">zDirectory);<br>
&nbsp;&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">journalOpen&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #800080">1</span><span style="color: #000000">;<br>
&nbsp;&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">journalStarted&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #800080">0</span><span style="color: #000000">;<br>
&nbsp;&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">needSync&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #800080">0</span><span style="color: #000000">;<br>
&nbsp;&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">alwaysRollback&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #800080">0</span><span style="color: #000000">;<br>
&nbsp;&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">nRec&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #800080">0</span><span style="color: #000000">;<br>
&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">errCode&nbsp;){<br>
&nbsp;&nbsp;&nbsp;&nbsp;rc&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">errCode;<br>
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">goto</span><span style="color: #000000">&nbsp;failed_to_open_journal;<br>
&nbsp;&nbsp;}<br>
&nbsp;&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">origDbSize&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">dbSize;<br>
&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">写入日志文件的header---24个字节</span><span style="color: #008000"><br>
</span><span style="color: #000000">&nbsp;&nbsp;rc&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;writeJournalHdr(pPager);<br>
<br>
&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">stmtAutoopen&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;rc</span><span style="color: #000000">==</span><span style="color: #000000">SQLITE_OK&nbsp;){<br>
&nbsp;&nbsp;&nbsp;&nbsp;rc&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;sqlite3pager_stmt_begin(pPager);<br>
&nbsp;&nbsp;}<br>
&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;rc</span><span style="color: #000000">!=</span><span style="color: #000000">SQLITE_OK&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;rc</span><span style="color: #000000">!=</span><span style="color: #000000">SQLITE_NOMEM&nbsp;){<br>
&nbsp;&nbsp;&nbsp;&nbsp;rc&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;pager_unwritelock(pPager);<br>
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;rc</span><span style="color: #000000">==</span><span style="color: #000000">SQLITE_OK&nbsp;){<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rc&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;SQLITE_FULL;<br>
&nbsp;&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;}<br>
&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;rc;<br>
<br>
failed_to_open_journal:<br>
&nbsp;&nbsp;sqliteFree(pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">aInJournal);<br>
&nbsp;&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">aInJournal&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #800080">0</span><span style="color: #000000">;<br>
&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;rc</span><span style="color: #000000">==</span><span style="color: #000000">SQLITE_NOMEM&nbsp;){<br>
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">/*</span><span style="color: #008000">&nbsp;If&nbsp;this&nbsp;was&nbsp;a&nbsp;malloc()&nbsp;failure,&nbsp;then&nbsp;we&nbsp;will&nbsp;not&nbsp;be&nbsp;closing&nbsp;the&nbsp;pager<br>
&nbsp;&nbsp;&nbsp;&nbsp;**&nbsp;file.&nbsp;So&nbsp;delete&nbsp;any&nbsp;journal&nbsp;file&nbsp;we&nbsp;may&nbsp;have&nbsp;just&nbsp;created.&nbsp;Otherwise,<br>
&nbsp;&nbsp;&nbsp;&nbsp;**&nbsp;the&nbsp;system&nbsp;will&nbsp;get&nbsp;confused,&nbsp;we&nbsp;have&nbsp;a&nbsp;read-lock&nbsp;on&nbsp;the&nbsp;file&nbsp;and&nbsp;a<br>
&nbsp;&nbsp;&nbsp;&nbsp;**&nbsp;mysterious&nbsp;journal&nbsp;has&nbsp;appeared&nbsp;in&nbsp;the&nbsp;filesystem.<br>
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">*/</span><span style="color: #000000"><br>
&nbsp;&nbsp;&nbsp;&nbsp;sqlite3OsDelete(pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">zJournal);<br>
&nbsp;&nbsp;}</span><span style="color: #0000ff">else</span><span style="color: #000000">{<br>
&nbsp;&nbsp;&nbsp;&nbsp;sqlite3OsUnlock(pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">fd,&nbsp;NO_LOCK);<br>
&nbsp;&nbsp;&nbsp;&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">state&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;PAGER_UNLOCK;<br>
&nbsp;&nbsp;}<br>
&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;rc;<br>
}<br>
<br>
</span><span style="color: #008000">/*</span><span style="color: #008000">写入日志文件头<br>
**journal&nbsp;header的格式如下:<br>
**&nbsp;-&nbsp;8&nbsp;bytes:&nbsp;标志日志文件的魔数<br>
**&nbsp;-&nbsp;4&nbsp;bytes:&nbsp;日志文件中记录数<br>
**&nbsp;-&nbsp;4&nbsp;bytes:&nbsp;Random&nbsp;number&nbsp;used&nbsp;for&nbsp;page&nbsp;hash.<br>
**&nbsp;-&nbsp;4&nbsp;bytes:&nbsp;原来数据库的大小(kb)<br>
**&nbsp;-&nbsp;4&nbsp;bytes:&nbsp;扇区大小512byte<br>
</span><span style="color: #008000">*/</span><span style="color: #000000"><br>
</span><span style="color: #0000ff">static</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;writeJournalHdr(Pager&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">pPager){<br>
&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">日志文件头</span><span style="color: #008000"><br>
</span><span style="color: #000000">&nbsp;&nbsp;</span><span style="color: #0000ff">char</span><span style="color: #000000">&nbsp;zHeader[</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(aJournalMagic)</span><span style="color: #000000">+</span><span style="color: #800080">16</span><span style="color: #000000">];<br>
<br>
&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;rc&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;seekJournalHdr(pPager);<br>
&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;rc&nbsp;)&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;rc;<br>
<br>
&nbsp;&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">journalHdr&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">journalOff;<br>
&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">stmtHdrOff</span><span style="color: #000000">==</span><span style="color: #800080">0</span><span style="color: #000000">&nbsp;){<br>
&nbsp;&nbsp;&nbsp;&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">stmtHdrOff&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">journalHdr;<br>
&nbsp;&nbsp;}<br>
&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">设置文件指针指向header之后</span><span style="color: #008000"><br>
</span><span style="color: #000000">&nbsp;&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">journalOff&nbsp;</span><span style="color: #000000">+=</span><span style="color: #000000">&nbsp;JOURNAL_HDR_SZ(pPager);<br>
<br>
&nbsp;&nbsp;</span><span style="color: #008000">/*</span><span style="color: #008000">&nbsp;FIX&nbsp;ME:&nbsp;<br>
&nbsp;&nbsp;**<br>
&nbsp;&nbsp;**&nbsp;Possibly&nbsp;for&nbsp;a&nbsp;pager&nbsp;not&nbsp;in&nbsp;no-sync&nbsp;mode,&nbsp;the&nbsp;journal&nbsp;magic&nbsp;should&nbsp;not<br>
&nbsp;&nbsp;**&nbsp;be&nbsp;written&nbsp;until&nbsp;nRec&nbsp;is&nbsp;filled&nbsp;in&nbsp;as&nbsp;part&nbsp;of&nbsp;next&nbsp;syncJournal().&nbsp;<br>
&nbsp;&nbsp;**<br>
&nbsp;&nbsp;**&nbsp;Actually&nbsp;maybe&nbsp;the&nbsp;whole&nbsp;journal&nbsp;header&nbsp;should&nbsp;be&nbsp;delayed&nbsp;until&nbsp;that<br>
&nbsp;&nbsp;**&nbsp;point.&nbsp;Think&nbsp;about&nbsp;this.<br>
&nbsp;&nbsp;</span><span style="color: #008000">*/</span><span style="color: #000000"><br>
&nbsp;&nbsp;memcpy(zHeader,&nbsp;aJournalMagic,&nbsp;</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(aJournalMagic));<br>
&nbsp;&nbsp;</span><span style="color: #008000">/*</span><span style="color: #008000">&nbsp;The&nbsp;nRec&nbsp;Field.&nbsp;0xFFFFFFFF&nbsp;for&nbsp;no-sync&nbsp;journals.&nbsp;</span><span style="color: #008000">*/</span><span style="color: #000000"><br>
&nbsp;&nbsp;put32bits(</span><span style="color: #000000">&amp;</span><span style="color: #000000">zHeader[</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(aJournalMagic)],&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">noSync&nbsp;</span><span style="color: #000000">?</span><span style="color: #000000">&nbsp;</span><span style="color: #800080">0xffffffff</span><span style="color: #000000">&nbsp;:&nbsp;</span><span style="color: #800080">0</span><span style="color: #000000">);<br>
&nbsp;&nbsp;</span><span style="color: #008000">/*</span><span style="color: #008000">&nbsp;The&nbsp;random&nbsp;check-hash&nbsp;initialiser&nbsp;</span><span style="color: #008000">*/</span><span style="color: #000000">&nbsp;<br>
&nbsp;&nbsp;sqlite3Randomness(</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">cksumInit),&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">cksumInit);<br>
&nbsp;&nbsp;put32bits(</span><span style="color: #000000">&amp;</span><span style="color: #000000">zHeader[</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(aJournalMagic)</span><span style="color: #000000">+</span><span style="color: #800080">4</span><span style="color: #000000">],&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">cksumInit);<br>
&nbsp;&nbsp;</span><span style="color: #008000">/*</span><span style="color: #008000">&nbsp;The&nbsp;initial&nbsp;database&nbsp;size&nbsp;</span><span style="color: #008000">*/</span><span style="color: #000000"><br>
&nbsp;&nbsp;put32bits(</span><span style="color: #000000">&amp;</span><span style="color: #000000">zHeader[</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(aJournalMagic)</span><span style="color: #000000">+</span><span style="color: #800080">8</span><span style="color: #000000">],&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">dbSize);<br>
&nbsp;&nbsp;</span><span style="color: #008000">/*</span><span style="color: #008000">&nbsp;The&nbsp;assumed&nbsp;sector&nbsp;size&nbsp;for&nbsp;this&nbsp;process&nbsp;</span><span style="color: #008000">*/</span><span style="color: #000000"><br>
&nbsp;&nbsp;put32bits(</span><span style="color: #000000">&amp;</span><span style="color: #000000">zHeader[</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(aJournalMagic)</span><span style="color: #000000">+</span><span style="color: #800080">12</span><span style="color: #000000">],&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">sectorSize);<br>
&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">写入文件头</span><span style="color: #008000"><br>
</span><span style="color: #000000">&nbsp;&nbsp;rc&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;sqlite3OsWrite(pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">jfd,&nbsp;zHeader,&nbsp;</span><span style="color: #0000ff">sizeof</span><span style="color: #000000">(zHeader));<br>
<br>
&nbsp;&nbsp;</span><span style="color: #008000">/*</span><span style="color: #008000">&nbsp;The&nbsp;journal&nbsp;header&nbsp;has&nbsp;been&nbsp;written&nbsp;successfully.&nbsp;Seek&nbsp;the&nbsp;journal<br>
&nbsp;&nbsp;**&nbsp;file&nbsp;descriptor&nbsp;to&nbsp;the&nbsp;end&nbsp;of&nbsp;the&nbsp;journal&nbsp;header&nbsp;sector.<br>
&nbsp;&nbsp;</span><span style="color: #008000">*/</span><span style="color: #000000"><br>
&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;rc</span><span style="color: #000000">==</span><span style="color: #000000">SQLITE_OK&nbsp;){<br>
&nbsp;&nbsp;&nbsp;&nbsp;rc&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;sqlite3OsSeek(pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">jfd,&nbsp;pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">journalOff</span><span style="color: #000000">-</span><span style="color: #800080">1</span><span style="color: #000000">);<br>
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(&nbsp;rc</span><span style="color: #000000">==</span><span style="color: #000000">SQLITE_OK&nbsp;){<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rc&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;sqlite3OsWrite(pPager</span><span style="color: #000000">-&gt;</span><span style="color: #000000">jfd,&nbsp;</span><span style="color: #800000">"</span><span style="color: #800000">\000</span><span style="color: #800000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #800080">1</span><span style="color: #000000">);<br>
&nbsp;&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;}<br>
&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;rc;<br>
}<br>
<br>
</span></span></div>
</font><p><font face="Verdana"></font>&nbsp;其实现过程如下图所示：</p>
<p>&nbsp;</p>
<p><img height="270" alt="" src="./SQLite入门与分析(四)---Page Cache之事务处理(1) - YY哥 - 博客园_files/sqlite04-01.GIF" width="427" border="0"></p>
<p>&nbsp;</p>
<p>主要参考：<font face="Verdana">http://www.sqlite.org/atomiccommit.html</font></p>
 </div><div id="MySignature"></div>
<div class="clear"></div>
<div id="blog_post_info_block">
<div id="BlogPostCategory">分类: <a href="http://www.cnblogs.com/hustcat/category/175618.html">数据库技术</a></div>
<div id="EntryTag"></div>
<div id="blog_post_info"><div id="green_channel">
<a href="javascript:void(0);" id="green_channel_digg" onclick="DiggIt(1398558,cb_blogId,1);green_channel_success(this,&#39;谢谢推荐！&#39;);">好文要顶</a>
<a id="green_channel_follow" onclick="c_follow();" href="javascript:void(0);">关注我</a>
<a id="green_channel_favorite" onclick="AddToWz(cb_entryId);return false;" href="javascript:void(0);">收藏该文</a><a id="green_channel_contact" href="http://msg.cnblogs.com/send/YY%E5%93%A5" target="_blank">联系我</a>
<a id="green_channel_weibo" href="javascript:void(0);" title="分享至新浪微博" onclick="ShareToTsina()"><img src="./SQLite入门与分析(四)---Page Cache之事务处理(1) - YY哥 - 博客园_files/icon_weibo_24.png" alt=""></a>
<a id="green_channel_wechat" href="javascript:void(0);" title="分享至微信" onclick="shareOnWechat()"><img src="./SQLite入门与分析(四)---Page Cache之事务处理(1) - YY哥 - 博客园_files/wechat.png" alt=""></a>
</div>
<div id="author_profile">
<div id="author_profile_info" class="author_profile_info">
<a href="http://home.cnblogs.com/u/hustcat/" target="_blank"><img src="./SQLite入门与分析(四)---Page Cache之事务处理(1) - YY哥 - 博客园_files/sample_face.gif" class="author_avatar" alt=""></a>
<div id="author_profile_detail" class="author_profile_info">
<a href="http://home.cnblogs.com/u/hustcat/">YY哥</a><br>
<a href="http://home.cnblogs.com/u/hustcat/followees">关注 - 2</a><br>
<a href="http://home.cnblogs.com/u/hustcat/followers">粉丝 - 528</a>
</div>
</div>
<div class="clear"></div>
<div id="author_profile_honor"></div>
<div id="author_profile_follow">
    <a href="javascript:void(0);" onclick="c_follow();return false;">+加关注</a>
</div>
</div>
<div id="div_digg">										
    <div class="diggit" onclick="votePost(1398558,&#39;Digg&#39;)">
        <span class="diggnum" id="digg_count">1</span>
    </div>
	<div class="buryit" onclick="votePost(1398558,&#39;Bury&#39;)"> 
		<span class="burynum" id="bury_count">0</span>
	</div>
	<div class="clear"></div>	
	<div class="diggword" id="digg_tips">
    (请您对文章做出评价)
    </div>	
</div>
</div>
<div class="clear"></div>
<div id="post_next_prev"><a href="http://www.cnblogs.com/hustcat/archive/2009/02/17/1392746.html" class="p_n_p_prefix">« </a> 上一篇：<a href="http://www.cnblogs.com/hustcat/archive/2009/02/17/1392746.html" title="发布于2009-02-17 21:12">SQLite入门与分析(三)---内核概述(2) </a><br><a href="http://www.cnblogs.com/hustcat/archive/2009/02/26/1398774.html" class="p_n_p_prefix">» </a> 下一篇：<a href="http://www.cnblogs.com/hustcat/archive/2009/02/26/1398774.html" title="发布于2009-02-26 14:16">SQLite入门与分析(四)---Page Cache之事务处理(2) </a><br></div>
</div>


		</div>
		<div class="postDesc">posted @ <span id="post-date">2009-02-26 10:45</span> <a href="http://www.cnblogs.com/hustcat/">YY哥</a> 阅读(<span id="post_view_count">8793</span>) 评论(<span id="post_comment_count">8</span>)  <a href="http://i.cnblogs.com/EditPosts.aspx?postid=1398558" rel="nofollow">编辑</a> <a href="http://www.cnblogs.com/hustcat/archive/2009/02/26/1398558.html#" onclick="AddToWz(1398558);return false;">收藏</a></div>
	</div>
	<script type="text/javascript">var allowComments=true,isLogined=false,cb_blogId=26761,cb_entryId=1398558,cb_blogApp=currentBlogApp,cb_blogUserGuid='a9743d0b-63cf-dd11-9e4d-001cf0cd104b',cb_entryCreatedDate='2009/2/26 10:45:00';loadViewCount(cb_entryId);</script>
	
</div><!--end: topics 文章、评论容器-->
</div><a name="!comments"></a><div id="blog-comments-placeholder"><div id="comments_pager_top"></div>
<br>
<div class="feedback_area_title">评论列表</div>
<div class="feedbackNoItems"></div>	

		<div class="feedbackItem">
			<div class="feedbackListSubtitle">
				<div class="feedbackManage">
					&nbsp;&nbsp;<span class="comment_actions"></span>
				</div>
				<a href="http://www.cnblogs.com/hustcat/archive/2009/02/26/1398558.html#1461890" class="layer">#1楼</a><a name="1461890" id="comment_anchor_1461890"></a>  <span class="comment_date">2009-02-26 11:44</span> <a id="ctl00_CommentList_NameLink_0" href="http://www.cnitblog.com/r.aspx?url=http://www.cppblog.com/true" rel="nofllow" target="_blank">true[未注册用户]</a>
			</div>
			<div class="feedbackCon">
				<div id="comment_body_1461890" class="blog_comment_body">感谢的同时，期待下文</div>
			</div>
		</div>
	
		<div class="feedbackItem">
			<div class="feedbackListSubtitle">
				<div class="feedbackManage">
					&nbsp;&nbsp;<span class="comment_actions"></span>
				</div>
				<a href="http://www.cnblogs.com/hustcat/archive/2009/02/26/1398558.html#1462272" class="layer">#2楼</a><a name="1462272" id="comment_anchor_1462272"></a>[<span class="louzhu">楼主</span>]  <span class="comment_date">2009-02-26 16:59</span> <a id="a_comment_author_1462272" href="http://www.cnblogs.com/hustcat/" target="_blank">YY哥</a> <a href="http://msg.cnblogs.com/send/YY%E5%93%A5" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
			</div>
			<div class="feedbackCon">
				<div id="comment_body_1462272" class="blog_comment_body">@true<br>不客气</div><div class="comment_vote"><a href="javascript:void(0);" class="comment_digg" onclick="return voteComment(1462272,&#39;Digg&#39;,this)">支持(0)</a><a href="javascript:void(0);" class="comment_bury" onclick="return voteComment(1462272,&#39;Bury&#39;,this)">反对(0)</a></div>
			</div>
		</div>
	
		<div class="feedbackItem">
			<div class="feedbackListSubtitle">
				<div class="feedbackManage">
					&nbsp;&nbsp;<span class="comment_actions"></span>
				</div>
				<a href="http://www.cnblogs.com/hustcat/archive/2009/02/26/1398558.html#1462600" class="layer">#3楼</a><a name="1462600" id="comment_anchor_1462600"></a>  <span class="comment_date">2009-02-26 23:56</span> <a id="ctl00_CommentList_NameLink_2" target="_blank">ajax+u[未注册用户]</a>
			</div>
			<div class="feedbackCon">
				<div id="comment_body_1462600" class="blog_comment_body">继续，最好将一下虚拟机</div>
			</div>
		</div>
	
		<div class="feedbackItem">
			<div class="feedbackListSubtitle">
				<div class="feedbackManage">
					&nbsp;&nbsp;<span class="comment_actions"></span>
				</div>
				<a href="http://www.cnblogs.com/hustcat/archive/2009/02/26/1398558.html#1468051" class="layer">#4楼</a><a name="1468051" id="comment_anchor_1468051"></a>  <span class="comment_date">2009-03-05 08:57</span> <a id="a_comment_author_1468051" href="http://www.cnblogs.com/soli/" target="_blank">Soli</a> <a href="http://msg.cnblogs.com/send/Soli" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
			</div>
			<div class="feedbackCon">
				<div id="comment_body_1468051" class="blog_comment_body">Not bad!</div><div class="comment_vote"><a href="javascript:void(0);" class="comment_digg" onclick="return voteComment(1468051,&#39;Digg&#39;,this)">支持(0)</a><a href="javascript:void(0);" class="comment_bury" onclick="return voteComment(1468051,&#39;Bury&#39;,this)">反对(0)</a></div><span id="comment_1468051_avatar" style="display:none;">http://pic.cnblogs.com/face/u1946.jpg</span>
			</div>
		</div>
	
		<div class="feedbackItem">
			<div class="feedbackListSubtitle">
				<div class="feedbackManage">
					&nbsp;&nbsp;<span class="comment_actions"></span>
				</div>
				<a href="http://www.cnblogs.com/hustcat/archive/2009/02/26/1398558.html#1838212" class="layer">#5楼</a><a name="1838212" id="comment_anchor_1838212"></a>  <span class="comment_date">2010-06-01 23:43</span> <a id="a_comment_author_1838212" href="http://home.cnblogs.com/u/137126/" target="_blank">MichaelMj</a> <a href="http://msg.cnblogs.com/send/MichaelMj" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
			</div>
			<div class="feedbackCon">
				<div id="comment_body_1838212" class="blog_comment_body">您讲的很好，使我受益匪浅。我想请教一个问题，为什么SQLiite要用到OS的BUFFER，而不自己设计缓存管理器？</div><div class="comment_vote"><a href="javascript:void(0);" class="comment_digg" onclick="return voteComment(1838212,&#39;Digg&#39;,this)">支持(0)</a><a href="javascript:void(0);" class="comment_bury" onclick="return voteComment(1838212,&#39;Bury&#39;,this)">反对(0)</a></div>
			</div>
		</div>
	
		<div class="feedbackItem">
			<div class="feedbackListSubtitle">
				<div class="feedbackManage">
					&nbsp;&nbsp;<span class="comment_actions"></span>
				</div>
				<a href="http://www.cnblogs.com/hustcat/archive/2009/02/26/1398558.html#1839201" class="layer">#6楼</a><a name="1839201" id="comment_anchor_1839201"></a>[<span class="louzhu">楼主</span>]  <span class="comment_date">2010-06-02 21:32</span> <a id="a_comment_author_1839201" href="http://www.cnblogs.com/hustcat/" target="_blank">YY哥</a> <a href="http://msg.cnblogs.com/send/YY%E5%93%A5" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
			</div>
			<div class="feedbackCon">
				<div id="comment_body_1839201" class="blog_comment_body"><a href="http://www.cnblogs.com/hustcat/archive/2009/02/26/1398558.html#1838212" title="查看所回复的评论" onclick="commentManager.renderComments(0,50,1838212);">@</a>MichaelMj<br>一般来说，只有大型通用DBMS才会放弃使用OS的BUFFER，因为它有足够的内存，这样，一方便便于管理，一方面速度更快（节省了从内核态的BUFFER拷贝数据到用户态的BUFFER）。但是，SQLite作为嵌入式数据库，受到它所应用的设备资源。所以，它的缓冲块都是按需从OS申请的，这样对内存的使用更少。这也是SQLite消耗内存少的原因之一。</div><div class="comment_vote"><a href="javascript:void(0);" class="comment_digg" onclick="return voteComment(1839201,&#39;Digg&#39;,this)">支持(0)</a><a href="javascript:void(0);" class="comment_bury" onclick="return voteComment(1839201,&#39;Bury&#39;,this)">反对(0)</a></div>
			</div>
		</div>
	
		<div class="feedbackItem">
			<div class="feedbackListSubtitle">
				<div class="feedbackManage">
					&nbsp;&nbsp;<span class="comment_actions"></span>
				</div>
				<a href="http://www.cnblogs.com/hustcat/archive/2009/02/26/1398558.html#1839552" class="layer">#7楼</a><a name="1839552" id="comment_anchor_1839552"></a>  <span class="comment_date">2010-06-03 10:27</span> <a id="a_comment_author_1839552" href="http://www.cnblogs.com/MichaelMj/" target="_blank">MichaelMj</a> <a href="http://msg.cnblogs.com/send/MichaelMj" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
			</div>
			<div class="feedbackCon">
				<div id="comment_body_1839552" class="blog_comment_body"><a href="http://www.cnblogs.com/hustcat/archive/2009/02/26/1398558.html#1839201" title="查看所回复的评论" onclick="commentManager.renderComments(0,50,1839201);">@</a>arrowcat<br>自己编写缓存管理器也可以实时监测内存的空间，动态的增减缓存的大小。或由用户来确定缓冲区的大小。并能够根据用户的要求或者嵌入式设备的不同来确定缓存替代策略，以达到最少的IO次数。所以我觉得如果SQLite自己设计缓存管理器会提高它的性能（缺点是编程工作量和可执行程序的增大）。</div><div class="comment_vote"><a href="javascript:void(0);" class="comment_digg" onclick="return voteComment(1839552,&#39;Digg&#39;,this)">支持(0)</a><a href="javascript:void(0);" class="comment_bury" onclick="return voteComment(1839552,&#39;Bury&#39;,this)">反对(0)</a></div>
			</div>
		</div>
	
		<div class="feedbackItem">
			<div class="feedbackListSubtitle">
				<div class="feedbackManage">
					&nbsp;&nbsp;<span class="comment_actions"></span>
				</div>
				<a href="http://www.cnblogs.com/hustcat/archive/2009/02/26/1398558.html#1840185" class="layer">#8楼</a><a name="1840185" id="comment_anchor_1840185"></a>[<span class="louzhu">楼主</span>]<span id="comment-maxId" style="display:none;">1840185</span><span id="comment-maxDate" style="display:none;">2010/6/3 22:33:14</span>  <span class="comment_date">2010-06-03 22:33</span> <a id="a_comment_author_1840185" href="http://www.cnblogs.com/hustcat/" target="_blank">YY哥</a> <a href="http://msg.cnblogs.com/send/YY%E5%93%A5" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
			</div>
			<div class="feedbackCon">
				<div id="comment_body_1840185" class="blog_comment_body"><a href="http://www.cnblogs.com/hustcat/archive/2009/02/26/1398558.html#1839552" title="查看所回复的评论" onclick="commentManager.renderComments(0,50,1839552);">@</a>MichaelMj<br>我想你理解错我的意思了。SQLite并不是没有Buffer管理系统，相反，它做的还比较有意思。但是它为什么还要用OS Buffer?我认为这与它的I/O方式和缓冲块的内存分配有关。一方面，它在系统初始化，并不是分配一大块内存作为缓冲区(而通用DBMS是这样做的)；另一方面，它使用简单的同步I/O。SQLite作为嵌入式数据库，它没有必要把I/O搞那么复杂，而且它本身也是单线程，异步I/O往往需要多线程的支持。如果它不用OS的buffer，它进行I/O时，OS只支读取当前块，而由于它应用的环境内存较少，可以经常涉及页面换进换出，这样带来大量的I/O。如果使用OS buffer，一般来说，OS都会相邻的数据缓存在OS的buffer，这样就能减少实际I/O的次数，从而降低I/O对系统性能的影响。以上纯属个人愚见，慎采纳。</div><div class="comment_vote"><a href="javascript:void(0);" class="comment_digg" onclick="return voteComment(1840185,&#39;Digg&#39;,this)">支持(0)</a><a href="javascript:void(0);" class="comment_bury" onclick="return voteComment(1840185,&#39;Bury&#39;,this)">反对(0)</a></div>
			</div>
		</div>
	<div id="comments_pager_bottom"></div></div><script type="text/javascript">var commentManager = new blogCommentManager();commentManager.renderComments(0);</script>
<div id="comment_form" class="commentform">
<a name="commentform"></a>
<div id="divCommentShow"></div>
<div id="comment_nav"><span id="span_refresh_tips"></span><a href="javascript:void(0);" onclick="return RefreshCommentList();" id="lnk_RefreshComments" runat="server" clientidmode="Static">刷新评论</a><a href="http://www.cnblogs.com/hustcat/archive/2009/02/26/1398558.html#" onclick="return RefreshPage();">刷新页面</a><a href="http://www.cnblogs.com/hustcat/archive/2009/02/26/1398558.html#top">返回顶部</a></div>
<div id="comment_form_container"><div class="login_tips">注册用户登录后才能发表评论，请 <a rel="nofollow" href="javascript:void(0);" class="underline" onclick="return login(&#39;commentform&#39;);">登录</a> 或 <a rel="nofollow" href="javascript:void(0);" class="underline" onclick="return register();">注册</a>，<a href="http://www.cnblogs.com/">访问</a>网站首页。</div></div>
<div class="ad_text_commentbox" id="ad_text_under_commentbox"></div>
<div id="ad_t2"><a href="http://www.ucancode.com/index.htm" target="_blank">【推荐】50万行VC++源码: 大型组态工控、电力仿真CAD与GIS源码库</a><br><a href="http://www.rongcloud.cn/" target="_blank">【推荐】融云即时通讯云－专注为 App 开发者提供IM云服务</a><br><a href="http://click.aliyun.com/m/3037/" target="_blank">【阿里云SSD云盘】速度行业领先</a><br></div>
<div id="opt_under_post"></div>
<div id="ad_c1" class="c_ad_block"><a href="http://q.cnblogs.com/" target="_blank"><img width="300" height="250" src="./SQLite入门与分析(四)---Page Cache之事务处理(1) - YY哥 - 博客园_files/not-to-stop-questioning.jpg" alt="博问" title="博问"></a></div>
<div id="under_post_news"><div class="itnews c_ad_block"><b>最新IT新闻</b>:<br> ·  <a href="http://news.cnblogs.com/n/539687/" target="_blank">怎样交付业余项目</a><br> ·  <a href="http://news.cnblogs.com/n/539774/" target="_blank">《黑暗之魂3》新预告片公布 国区Steam预购仅199元</a><br> ·  <a href="http://news.cnblogs.com/n/539773/" target="_blank">梅西暖人一幕：送签名球衣圆梦塑料男孩</a><br> ·  <a href="http://news.cnblogs.com/n/539772/" target="_blank">中国科学家培育出人工精子 给不育男士带来福音</a><br> ·  <a href="http://news.cnblogs.com/n/539771/" target="_blank">市场份额已不足1% Opera欲推新浏览器摆脱困境</a><br>» <a href="http://news.cnblogs.com/" title="IT新闻" target="_blank">更多新闻...</a></div></div>
<div id="under_post_kb"><div class="itnews c_ad_block" id="kb_block"><b>最新知识库文章</b>:<br><div id="kb_recent"> ·  <a href="http://kb.cnblogs.com/page/538249/" target="_blank">谷歌背后的数学</a><br> ·  <a href="http://kb.cnblogs.com/page/533808/" target="_blank">Medium开发团队谈架构设计</a><br> ·  <a href="http://kb.cnblogs.com/page/539274/" target="_blank">理解“渐进增强(Progressive Enhancement)”</a><br> ·  <a href="http://kb.cnblogs.com/page/534571/" target="_blank">为什么说DOM操作很慢</a><br> ·  <a href="http://kb.cnblogs.com/page/527518/" target="_blank">为什么你应该尝试全栈</a><br></div>» <a href="http://kb.cnblogs.com/" target="_blank">更多知识库文章...</a></div></div>
<div id="HistoryToday" class="c_ad_block"></div>
<script type="text/javascript">
$(function () {
    setTimeout(function () { incrementViewCount(cb_entryId); }, 50);
    deliverAdT2();
    deliverAdC1();    
    loadNewsAndKb();
    loadBlogSignature();
    LoadPostInfoBlock(cb_blogId, cb_entryId, cb_blogApp, cb_blogUserGuid);
    GetPrevNextPost(cb_entryId, cb_blogId, cb_entryCreatedDate);
    loadOptUnderPost();
    GetHistoryToday(cb_blogId, cb_blogApp, cb_entryCreatedDate);    
});
</script>
</div>


	</div><!--end: forFlow -->
	</div><!--end: mainContent 主体内容容器-->

	<div id="sideBar">
		<div id="sideBarMain">
			
<!--done-->
<div class="newsItem">
<h3 class="catListTitle">公告</h3>
	<div id="blog-news"><p><strong>
</strong></p><div align="center"><strong><img border="0" alt="" src="./SQLite入门与分析(四)---Page Cache之事务处理(1) - YY哥 - 博客园_files/jim_gray.jpg" width="160" height="268"></strong></div>
<p>&nbsp;</p>
<p><strong>个人简介</strong></p>
<p>专业打杂程序员  @<a href="http://hustcat.github.io/">github</a></p><p>
<br>
</p><p><strong>联系方式</strong></p>
<p><a title="新浪微博" href="http://weibo.com/hustcat"><span style="font-family: Courier">新浪微博</span></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a title="腾讯微博" href="http://t.qq.com/hustcat">腾讯微博</a></p>
<p><br></p>
<p><!-- 博客园新闻频道引用代码 num-显示条数 --><a href="http://news.cnblogs.com/" target="_blank">IT新闻:</a><br></p><div style="display: none" id="__document_write_ajax_div-1"></div><div id="profile_block">昵称：<a href="http://home.cnblogs.com/u/hustcat/">YY哥</a><br>园龄：<a href="http://home.cnblogs.com/u/hustcat/" title="入园时间：2007-05-23">8年9个月</a><br>粉丝：<a href="http://home.cnblogs.com/u/hustcat/followers/">528</a><br>关注：<a href="http://home.cnblogs.com/u/hustcat/followees/">2</a><div id="p_b_follow"></div><div style="display: none" id="__document_write_ajax_div-2"></div></div></div><script type="text/javascript">loadBlogNews();</script>
</div>

			<div id="blog-calendar" style=""><table id="blogCalendar" class="Cal" cellspacing="0" cellpadding="0" title="日历">
	<tbody><tr><td colspan="7"><table class="CalTitle" cellspacing="0">
		<tbody><tr><td class="CalNextPrev"><a href="javascript:void(0);" onclick="loadBlogCalendar(&#39;2009/01/01&#39;);return false;">&lt;</a></td><td align="center">2009年2月</td><td class="CalNextPrev" align="right"><a href="javascript:void(0);" onclick="loadBlogCalendar(&#39;2009/03/01&#39;);return false;">&gt;</a></td></tr>
	</tbody></table></td></tr><tr><th class="CalDayHeader" align="center" abbr="日" scope="col">日</th><th class="CalDayHeader" align="center" abbr="一" scope="col">一</th><th class="CalDayHeader" align="center" abbr="二" scope="col">二</th><th class="CalDayHeader" align="center" abbr="三" scope="col">三</th><th class="CalDayHeader" align="center" abbr="四" scope="col">四</th><th class="CalDayHeader" align="center" abbr="五" scope="col">五</th><th class="CalDayHeader" align="center" abbr="六" scope="col">六</th></tr><tr><td class="CalOtherMonthDay" align="center">25</td><td class="CalOtherMonthDay" align="center">26</td><td class="CalOtherMonthDay" align="center">27</td><td class="CalOtherMonthDay" align="center">28</td><td class="CalOtherMonthDay" align="center">29</td><td class="CalOtherMonthDay" align="center">30</td><td class="CalOtherMonthDay" align="center">31</td></tr><tr><td class="CalWeekendDay" align="center"><a href="http://www.cnblogs.com/hustcat/archive/2009/02/01.html"><u>1</u></a></td><td align="center">2</td><td align="center">3</td><td align="center">4</td><td align="center">5</td><td align="center">6</td><td class="CalWeekendDay" align="center">7</td></tr><tr><td class="CalWeekendDay" align="center">8</td><td align="center">9</td><td align="center">10</td><td align="center"><a href="http://www.cnblogs.com/hustcat/archive/2009/02/11.html"><u>11</u></a></td><td align="center"><a href="http://www.cnblogs.com/hustcat/archive/2009/02/12.html"><u>12</u></a></td><td align="center"><a href="http://www.cnblogs.com/hustcat/archive/2009/02/13.html"><u>13</u></a></td><td class="CalWeekendDay" align="center"><a href="http://www.cnblogs.com/hustcat/archive/2009/02/14.html"><u>14</u></a></td></tr><tr><td class="CalWeekendDay" align="center"><a href="http://www.cnblogs.com/hustcat/archive/2009/02/15.html"><u>15</u></a></td><td align="center">16</td><td align="center"><a href="http://www.cnblogs.com/hustcat/archive/2009/02/17.html"><u>17</u></a></td><td align="center">18</td><td align="center">19</td><td align="center">20</td><td class="CalWeekendDay" align="center">21</td></tr><tr><td class="CalWeekendDay" align="center">22</td><td align="center">23</td><td align="center">24</td><td align="center">25</td><td align="center"><a href="http://www.cnblogs.com/hustcat/archive/2009/02/26.html"><u>26</u></a></td><td align="center">27</td><td class="CalWeekendDay" align="center">28</td></tr><tr><td class="CalOtherMonthDay" align="center">1</td><td class="CalOtherMonthDay" align="center">2</td><td class="CalOtherMonthDay" align="center">3</td><td class="CalOtherMonthDay" align="center">4</td><td class="CalOtherMonthDay" align="center">5</td><td class="CalOtherMonthDay" align="center">6</td><td class="CalOtherMonthDay" align="center">7</td></tr>
</tbody></table></div><script type="text/javascript">loadBlogDefaultCalendar();</script>
			
			<div id="leftcontentcontainer">
				<div id="blog-sidecolumn"><div id="sidebar_search" class="sidebar-block">
<div id="sidebar_search" class="mySearch">
<h3 class="catListTitle">搜索</h3>
<div id="sidebar_search_box">
<div id="widget_my_zzk" class="div_my_zzk"><input type="text" id="q" onkeydown="return zzk_go_enter(event);" class="input_my_zzk">&nbsp;<input onclick="zzk_go()" type="button" value="找找看" id="btnZzk" class="btn_my_zzk"></div>
<div id="widget_my_google" class="div_my_zzk"><input type="text" name="google_q" id="google_q" onkeydown="return google_go_enter(event)" class="input_my_zzk">&nbsp;<input onclick="google_go()" type="button" value="谷歌搜索" class="btn_my_zzk"></div>
</div>
</div>

</div><div id="sidebar_shortcut" class="sidebar-block">
<div class="catListLink">
<h3 class="catListTitle">常用链接</h3>
<ul>
<li><a href="http://www.cnblogs.com/hustcat/p/" title="我的博客的随笔列表">我的随笔</a></li><li><a href="http://www.cnblogs.com/hustcat/MyComments.html" title="我发表过的评论列表">我的评论</a></li><li><a href="http://www.cnblogs.com/hustcat/OtherPosts.html" title="我评论过的随笔列表">我的参与</a></li><li><a href="http://www.cnblogs.com/hustcat/RecentComments.html" title="我的博客的评论列表">最新评论</a></li><li><a href="http://www.cnblogs.com/hustcat/tag/" title="我的博客的标签列表">我的标签</a></li>
<li><a id="itemListLink" onclick="this.blur();WarpClass(&#39;itemListLink&#39;, &#39;itemListLin_con&#39;);return false;" href="http://www.cnblogs.com/hustcat/archive/2009/02/26/1398558.html#">更多链接</a></li>
</ul>
<div id="itemListLin_con" style="display:none;">
<ul>

</ul>
</div>
</div></div><div id="sidebar_categories">
<div id="sidebar_postcategory" class="catListPostCategory sidebar-block">
<h3 class="catListTitle">随笔分类</h3>

<ul>

<li><a id="CatList_LinkList_0_Link_0" href="http://www.cnblogs.com/hustcat/category/191424.html">Linux相关(26)</a> </li>

<li><a id="CatList_LinkList_0_Link_1" href="http://www.cnblogs.com/hustcat/category/214566.html">MySQL(11)</a> </li>

<li><a id="CatList_LinkList_0_Link_2" href="http://www.cnblogs.com/hustcat/category/175619.html">Others(3)</a> </li>

<li><a id="CatList_LinkList_0_Link_3" href="http://www.cnblogs.com/hustcat/category/139956.html">Web技术(12)</a> </li>

<li><a id="CatList_LinkList_0_Link_4" href="http://www.cnblogs.com/hustcat/category/183836.html">编程语言(15)</a> </li>

<li><a id="CatList_LinkList_0_Link_5" href="http://www.cnblogs.com/hustcat/category/605980.html">存储(1)</a> </li>

<li><a id="CatList_LinkList_0_Link_6" href="http://www.cnblogs.com/hustcat/category/130051.html">数据结构与算法(15)</a> </li>

<li><a id="CatList_LinkList_0_Link_7" href="http://www.cnblogs.com/hustcat/category/175618.html">数据库技术(30)</a> </li>

<li><a id="CatList_LinkList_0_Link_8" href="http://www.cnblogs.com/hustcat/category/196365.html">系统相关(3)</a> </li>

<li><a id="CatList_LinkList_0_Link_9" href="http://www.cnblogs.com/hustcat/category/427554.html">云计算与虚拟化(10)</a> </li>

</ul>

</div>

<div id="sidebar_postarchive" class="catListPostArchive sidebar-block">
<h3 class="catListTitle">随笔档案</h3>

<ul>

<li><a id="CatList_LinkList_1_Link_0" href="http://www.cnblogs.com/hustcat/archive/2014/11.html">2014年11月 (1)</a> </li>

<li><a id="CatList_LinkList_1_Link_1" href="http://www.cnblogs.com/hustcat/archive/2014/10.html">2014年10月 (5)</a> </li>

<li><a id="CatList_LinkList_1_Link_2" href="http://www.cnblogs.com/hustcat/archive/2014/09.html">2014年9月 (5)</a> </li>

<li><a id="CatList_LinkList_1_Link_3" href="http://www.cnblogs.com/hustcat/archive/2014/08.html">2014年8月 (5)</a> </li>

<li><a id="CatList_LinkList_1_Link_4" href="http://www.cnblogs.com/hustcat/archive/2014/07.html">2014年7月 (4)</a> </li>

<li><a id="CatList_LinkList_1_Link_5" href="http://www.cnblogs.com/hustcat/archive/2014/03.html">2014年3月 (1)</a> </li>

<li><a id="CatList_LinkList_1_Link_6" href="http://www.cnblogs.com/hustcat/archive/2013/09.html">2013年9月 (1)</a> </li>

<li><a id="CatList_LinkList_1_Link_7" href="http://www.cnblogs.com/hustcat/archive/2013/08.html">2013年8月 (1)</a> </li>

<li><a id="CatList_LinkList_1_Link_8" href="http://www.cnblogs.com/hustcat/archive/2013/02.html">2013年2月 (1)</a> </li>

<li><a id="CatList_LinkList_1_Link_9" href="http://www.cnblogs.com/hustcat/archive/2012/11.html">2012年11月 (4)</a> </li>

<li><a id="CatList_LinkList_1_Link_10" href="http://www.cnblogs.com/hustcat/archive/2012/01.html">2012年1月 (1)</a> </li>

<li><a id="CatList_LinkList_1_Link_11" href="http://www.cnblogs.com/hustcat/archive/2011/12.html">2011年12月 (1)</a> </li>

<li><a id="CatList_LinkList_1_Link_12" href="http://www.cnblogs.com/hustcat/archive/2011/10.html">2011年10月 (1)</a> </li>

<li><a id="CatList_LinkList_1_Link_13" href="http://www.cnblogs.com/hustcat/archive/2011/03.html">2011年3月 (1)</a> </li>

<li><a id="CatList_LinkList_1_Link_14" href="http://www.cnblogs.com/hustcat/archive/2010/09.html">2010年9月 (1)</a> </li>

<li><a id="CatList_LinkList_1_Link_15" href="http://www.cnblogs.com/hustcat/archive/2010/08.html">2010年8月 (1)</a> </li>

<li><a id="CatList_LinkList_1_Link_16" href="http://www.cnblogs.com/hustcat/archive/2010/07.html">2010年7月 (3)</a> </li>

<li><a id="CatList_LinkList_1_Link_17" href="http://www.cnblogs.com/hustcat/archive/2010/06.html">2010年6月 (2)</a> </li>

<li><a id="CatList_LinkList_1_Link_18" href="http://www.cnblogs.com/hustcat/archive/2010/05.html">2010年5月 (7)</a> </li>

<li><a id="CatList_LinkList_1_Link_19" href="http://www.cnblogs.com/hustcat/archive/2010/04.html">2010年4月 (1)</a> </li>

<li><a id="CatList_LinkList_1_Link_20" href="http://www.cnblogs.com/hustcat/archive/2010/03.html">2010年3月 (1)</a> </li>

<li><a id="CatList_LinkList_1_Link_21" href="http://www.cnblogs.com/hustcat/archive/2010/01.html">2010年1月 (1)</a> </li>

<li><a id="CatList_LinkList_1_Link_22" href="http://www.cnblogs.com/hustcat/archive/2009/12.html">2009年12月 (2)</a> </li>

<li><a id="CatList_LinkList_1_Link_23" href="http://www.cnblogs.com/hustcat/archive/2009/10.html">2009年10月 (2)</a> </li>

<li><a id="CatList_LinkList_1_Link_24" href="http://www.cnblogs.com/hustcat/archive/2009/09.html">2009年9月 (14)</a> </li>

<li><a id="CatList_LinkList_1_Link_25" href="http://www.cnblogs.com/hustcat/archive/2009/08.html">2009年8月 (4)</a> </li>

<li><a id="CatList_LinkList_1_Link_26" href="http://www.cnblogs.com/hustcat/archive/2009/06.html">2009年6月 (14)</a> </li>

<li><a id="CatList_LinkList_1_Link_27" href="http://www.cnblogs.com/hustcat/archive/2009/05.html">2009年5月 (3)</a> </li>

<li><a id="CatList_LinkList_1_Link_28" href="http://www.cnblogs.com/hustcat/archive/2009/04.html">2009年4月 (1)</a> </li>

<li><a id="CatList_LinkList_1_Link_29" href="http://www.cnblogs.com/hustcat/archive/2009/03.html">2009年3月 (3)</a> </li>

<li><a id="CatList_LinkList_1_Link_30" href="http://www.cnblogs.com/hustcat/archive/2009/02.html">2009年2月 (11)</a> </li>

<li><a id="CatList_LinkList_1_Link_31" href="http://www.cnblogs.com/hustcat/archive/2008/10.html">2008年10月 (7)</a> </li>

<li><a id="CatList_LinkList_1_Link_32" href="http://www.cnblogs.com/hustcat/archive/2008/08.html">2008年8月 (5)</a> </li>

<li><a id="CatList_LinkList_1_Link_33" href="http://www.cnblogs.com/hustcat/archive/2008/07.html">2008年7月 (1)</a> </li>

<li><a id="CatList_LinkList_1_Link_34" href="http://www.cnblogs.com/hustcat/archive/2008/06.html">2008年6月 (2)</a> </li>

<li><a id="CatList_LinkList_1_Link_35" href="http://www.cnblogs.com/hustcat/archive/2008/05.html">2008年5月 (2)</a> </li>

<li><a id="CatList_LinkList_1_Link_36" href="http://www.cnblogs.com/hustcat/archive/2008/04.html">2008年4月 (5)</a> </li>

</ul>

</div>

<div id="sidebar_kernel" class="catListkernel sidebar-block">
<h3 class="catListTitle">kernel</h3>

<ul>

<li><a id="CatList_LinkList_2_Link_0" href="http://wiki.zh-kernel.org/" rel="nofollow">kernel中文社区</a> </li>

<li><a id="CatList_LinkList_2_Link_1" href="http://ldn.linuxfoundation.org/" rel="nofollow">LDN</a> </li>

<li><a id="CatList_LinkList_2_Link_2" href="http://www.tldp.org/" rel="nofollow">The Linux Document Project</a> </li>

<li><a id="CatList_LinkList_2_Link_3" href="http://www.kernel.org/" rel="nofollow">The Linux Kernel Archives</a> </li>

</ul>

</div>

<div id="sidebar_links210847" class="catList sidebar-block">
<h3 class="catListTitle">manual</h3>

<ul>

<li><a id="CatList_LinkList_3_Link_0" href="http://www.cppreference.com/wiki/" rel="nofollow">cppreference</a> </li>

<li><a id="CatList_LinkList_3_Link_1" href="http://gcc.gnu.org/onlinedocs/" rel="nofollow">gcc manual</a> </li>

<li><a id="CatList_LinkList_3_Link_2" href="http://dev.mysql.com/doc/refman/5.1/zh/index.html" rel="nofollow">mysql manual</a> </li>

</ul>

</div>

<div id="sidebar_links198983" class="catList sidebar-block">
<h3 class="catListTitle">sites</h3>

<ul>

<li><a id="CatList_LinkList_4_Link_0" href="http://www.databasejournal.com/" rel="nofollow">Database Journal</a> </li>

<li><a id="CatList_LinkList_4_Link_1" href="http://mirrors.fedoraproject.org/publiclist/Fedora/" rel="nofollow">Fedora镜象</a> </li>

<li><a id="CatList_LinkList_4_Link_2" href="http://highscalability.com/" rel="nofollow">highscalability</a> </li>

<li><a id="CatList_LinkList_4_Link_3" href="https://eprints.kfupm.edu.sa/" rel="nofollow">KFUPM ePrints</a> </li>

<li><a id="CatList_LinkList_4_Link_4" href="http://www.die.net/" rel="nofollow">Linux docs</a> </li>

<li><a id="CatList_LinkList_4_Link_5" href="http://www.linuxjournal.com/" rel="nofollow">Linux Journal</a> </li>

<li><a id="CatList_LinkList_4_Link_6" href="http://nosql-database.org/" rel="nofollow">NoSQL</a> </li>

<li><a id="CatList_LinkList_4_Link_7" href="http://www.sqlite.org/" rel="nofollow">SQLite</a> </li>

</ul>

</div>

<div id="sidebar_technology website" class="catListtechnology website sidebar-block">
<h3 class="catListTitle">技术社区</h3>

<ul>

<li><a id="CatList_LinkList_5_Link_0" href="http://www.apache.org/" rel="nofollow">apache</a> </li>

<li><a id="CatList_LinkList_5_Link_1" href="http://www.csdn.net/" rel="nofollow">CSDN</a> </li>

<li><a id="CatList_LinkList_5_Link_2" href="http://www.ibm.com/developerworks/cn/" rel="nofollow">IBM-developerworks</a> </li>

<li><a id="CatList_LinkList_5_Link_3" href="http://www.lucene.com.cn/" rel="nofollow">lucene中国</a> </li>

<li><a id="CatList_LinkList_5_Link_4" href="http://www.nutchchina.com/" rel="nofollow">nutch中国</a> </li>

<li><a id="CatList_LinkList_5_Link_5" href="http://www.oldlinux.org/oldlinux/index.php" rel="nofollow">oldlinux</a> </li>

<li><a id="CatList_LinkList_5_Link_6" href="http://forums.oracle.com/forums/main.jspa?categoryID=84" rel="nofollow">oracle's forum</a> </li>

</ul>

</div>

</div><div id="sidebar_recentcomments" class="sidebar-block"><div id="recent_comments_wrap">
<div class="catListComment">
<h3 class="catListTitle">最新评论</h3>

	<div id="RecentCommentsBlock"><ul>
    <li class="recent_comment_title"><a href="http://www.cnblogs.com/hustcat/p/3993712.html#3345657">1. Re:Docker实践(6)—CentOS7上部署Kubernetes</a></li>
    <li class="recent_comment_body">Mark</li>
    <li class="recent_comment_author">--Ant</li>
    <li class="recent_comment_title"><a href="http://www.cnblogs.com/hustcat/p/4004889.html#3343804">2. Re:深入学习golang(4)—new与make</a></li>
    <li class="recent_comment_body">讲的让我懂了，反正我顶</li>
    <li class="recent_comment_author">--一页天书不分说</li>
    <li class="recent_comment_title"><a href="http://www.cnblogs.com/hustcat/archive/2009/09/17/1568738.html#3336424">3. Re:Linux网络协议栈(一)——Socket入门(1)</a></li>
    <li class="recent_comment_body">学习</li>
    <li class="recent_comment_author">--血洗女生宿舍</li>
    <li class="recent_comment_title"><a href="http://www.cnblogs.com/hustcat/archive/2009/09/17/1568765.html#3336421">4. Re:Linux网络协议栈(一)——Socket入门(2)</a></li>
    <li class="recent_comment_body">学习</li>
    <li class="recent_comment_author">--血洗女生宿舍</li>
    <li class="recent_comment_title"><a href="http://www.cnblogs.com/hustcat/archive/2009/10/28/1591648.html#3269030">5. Re:理解MySQL——索引与优化</a></li>
    <li class="recent_comment_body">楼主我收藏了</li>
    <li class="recent_comment_author">--Ｍ&amp;amp;N</li>
</ul>
</div>
</div>
</div></div><div id="sidebar_topviewedposts" class="sidebar-block"><div id="topview_posts_wrap">
<div class="catListView">
<h3 class="catListTitle">阅读排行榜</h3>
	<div id="TopViewPostsBlock"><ul><li><a href="http://www.cnblogs.com/hustcat/archive/2009/10/28/1591648.html">1. 理解MySQL——索引与优化(166180)</a></li><li><a href="http://www.cnblogs.com/hustcat/archive/2009/02/12/1389448.html">2. SQLite入门与分析(一)---简介(51843)</a></li><li><a href="http://www.cnblogs.com/hustcat/archive/2009/12/19/1627525.html">3. 理解MySQL——复制(Replication)(45305)</a></li><li><a href="http://www.cnblogs.com/hustcat/archive/2010/08/31/1814022.html">4. libevent源码分析(39126)</a></li><li><a href="http://www.cnblogs.com/hustcat/archive/2008/04/09/1144645.html">5. 算法系列---回溯算法(25309)</a></li></ul></div>
</div>
</div></div><div id="sidebar_topcommentedposts" class="sidebar-block"><div id="topfeedback_posts_wrap">
<div class="catListFeedback">
<h3 class="catListTitle">评论排行榜</h3>
	<div id="TopFeedbackPostsBlock"><ul><li><a href="http://www.cnblogs.com/hustcat/archive/2009/06/02/1494311.html">1. (i++)+(i++)与(++i)+(++i)(40)</a></li><li><a href="http://www.cnblogs.com/hustcat/archive/2009/02/12/1389448.html">2. SQLite入门与分析(一)---简介(31)</a></li><li><a href="http://www.cnblogs.com/hustcat/archive/2009/10/28/1591648.html">3. 理解MySQL——索引与优化(23)</a></li><li><a href="http://www.cnblogs.com/hustcat/archive/2010/01/27/1657821.html">4. 浅谈SQLite——实现与应用(21)</a></li><li><a href="http://www.cnblogs.com/hustcat/archive/2010/05/14/1735774.html">5. 一道算法题,求更好的解法(18)</a></li></ul></div>
</div>
</div></div><div id="sidebar_topdiggedposts" class="sidebar-block"><div id="topdigg_posts_wrap">
<div class="catListView">
<h3 class="catListTitle">推荐排行榜</h3>
<div id="TopDiggPostsBlock"><ul><li><a href="http://www.cnblogs.com/hustcat/archive/2009/10/28/1591648.html">1. 理解MySQL——索引与优化(30)</a></li><li><a href="http://www.cnblogs.com/hustcat/archive/2009/02/12/1389448.html">2. SQLite入门与分析(一)---简介(13)</a></li><li><a href="http://www.cnblogs.com/hustcat/archive/2010/08/31/1814022.html">3. libevent源码分析(12)</a></li><li><a href="http://www.cnblogs.com/hustcat/archive/2010/06/23/1762987.html">4. 浅谈SQLite——查询处理及优化(10)</a></li><li><a href="http://www.cnblogs.com/hustcat/archive/2012/01/11/2319249.html">5. 乱谈服务器编程(10)</a></li></ul></div>
</div></div></div></div><script type="text/javascript">loadBlogSideColumn();</script>
			</div>
			
		</div><!--end: sideBarMain -->
	</div><!--end: sideBar 侧边栏容器 -->
	<div class="clear"></div>
	</div><!--end: main -->
	<div class="clear"></div>
	<div id="footer">
		
<!--done-->
Copyright ©2016 YY哥
	</div><!--end: footer -->
</div><!--end: home 自定义的最大容器 -->


</body></html>